<!--{include(file='head.html')}-->
<script type="text/javascript" src="template/jslib/date/WdatePicker.js"></script>
<script type="text/javascript" src="template/jslib/tbox/tbox.js"></script>
<link rel="stylesheet" href="template/jslib/tbox/tbox.css" type="text/css" />


<div id="wrap">
	<!--{include('left.html')}-->
	
	<div id="maincont">
		<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
		<form action="<!--{url('admin','gift','giftsave')}-->" method="post" name="submitform" id="submitform">
		<div id="main_c">
		<!--{if $opertype == "edit"}-->
			<ul class="bk">
				<li>
					<label><em>*</em>主题：</label>
					<p>
						<input class="input_tx short" value="<!--{$gift.subject}-->" name="subject" id="subject" type="text"/>
					</p>
				</li>
				<li>
					<label><em>*</em>时间：</label>
					<p>
						<input class="input_tx short" value="<!--{date('Y-m-d',$gift.begintime)}-->" name="begintime" id="begintime" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
						-
						<input class="input_tx short" value="<!--{date('Y-m-d',$gift.endtime)}-->" name="endtime" id="endtime" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
					</p>
				</li>
				<li>
					<label><em>*</em>商品：</label>
					<p>
						<a href="javascript:void(0);" onclick="ItemSelect.popitem();return false;" class="bt_style2">选择商品</a>
						<span class="foritem"><!--{$gift.itemname}--></span>
						<input type="hidden" name="itemid" value="<!--{$gift.itemid}-->" id="itemid" />
					</p>
				</li>
				<li>
					<label><em>*</em>赠品：</label>
					<div class="listp">
						<a href="javascript:void(0);" onclick="ItemSelect.popgift();return false;" class="bt_style2">选择赠品</a>
						<table id="gift" border="0" cellspacing="0" cellpadding="0">
								<!--{$gifts = unserialize($gift.gift)}-->
								<!--{foreach $gifts gift}-->
									<tr>
										<td class="giftimg" width="50">
	<img src="<!--{$gift.gitemimg}-->_50x50.jpg" width="50" height="50" onerror="this.onerror='',this.src='images/nopicture.jpg'"/> 
										</td>
										<td class="giftname" width="200"><!--{$gift.gitemname}--></td>
										<td width="50"><input type="text" size="5" value="<!--{$gift.num}-->" name="num[<!--{$gift.gitemid}-->]"/></td>
										<td width="100">
											<a href="javascript:void(0);" class="up" onclick="$.oper.up(this);return false;"></a>
											<a href="javascript:void(0);" class="down" onclick="$.oper.down(this);return false;"></a>
											<a href="javascript:void(0);" class="del" onclick="$.oper.del(this);return false;"></a>
										</td>
									</tr>
								<!--{/foreach}-->
						</table>
						</div>
				</li>
			</ul>

			
		<!--{elseif $opertype=="add"}-->
			<ul class="bk">
				<li>
					<label><em>*</em>主题：</label>
					<p>
						<input class="input_tx short" value="" name="subject" id="subject" type="text"/>
					</p>
				</li>
				<li>
					<label><em>*</em>时间：</label>
					<p>
						<input class="input_tx short" value="" name="begintime" id="begintime" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
						-
						<input class="input_tx short" value="" name="endtime" id="endtime" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
					</p>
				</li>
				<li>
					<label><em>*</em>商品：</label>
					<p>
						<a href="javascript:void(0);" onclick="ItemSelect.popitem();return false;" class="bt_style2">选择商品</a>
						<span class="foritem"></span>
						<input type="hidden" name="itemid" value="" id="itemid" />
					</p>
				</li>
				<li>
					<label><em>*</em>赠品：</label>
					<div class="listp">
						<a href="javascript:void(0);" onclick="ItemSelect.popgift();return false;" class="bt_style2">选择赠品</a>
						<table id="gift"  border="0" cellspacing="0" cellpadding="0">
								
						</table>
					</div>
				</li>
			</ul>
		<!--{/if}-->
			<div class="bt_bk2">
				<input type="hidden" value="<!--{$opertype}-->" name="opertype" />
				<input type="hidden" value="<!--{def($giftid)}-->" name="giftid" />
				<a href="javascript:void(0);" class="btn" onclick="jssubmit('gift');return false;"><span>保存</span></a>
			</div>
		</div>
		</form>
		<b class="b4b"></b><b class="b3b"></b><b class="b2b"></b><b class="b1b"></b>
	</div>
</div>
<!--{include(file='foot.html')}-->
<table class="tableStyle none" border="0" cellspacing="0" cellpadding="0">
	<tbody id="forgift">
		<tr>
			<td class="giftimg" width="50"></td>
			<td class="giftname" width="200"></td>
			<td width="50"><input type="text" size="5" value="1" name="num[{itemid}]"/></td>
			<td width="100">
				<a href="javascript:void(0);" class="up" onclick="$.oper.up(this);return false;"></a>
				<a href="javascript:void(0);" class="down" onclick="$.oper.down(this);return false;"></a>
				<a href="javascript:void(0);" class="del" onclick="$.oper.del(this);return false;"></a>
			</td>
		</tr>
	</tbody>
</table>

<script type="text/javascript">
var ItemSelect = {
	popitem:function() {//弹出item选择框
		$.tbox.popup("<!--{url('admin','select','selectitem','type=select')}-->");
	},
	popgift:function() {//弹出gift选择框
		$.tbox.popup("<!--{url('admin','select','selectitem','type=gift')}-->");
	},
	selectitem:function(itemid){//选择item
		$("#itemid").val(itemid);
		$(".foritem").text($("#item_" + itemid).text());
		$.tbox.close();
	},
	selectgift:function(){//选择gift
		var ele = $("#listtbody").find("input:checked");
		var ids = $.util.checkedval(ele);
		$(ids).each(function(k,id){
			$html = $("#forgift").clone();
			$(".giftimg",$html).html($("#img_"+id).html());
			$(".giftname",$html).text($("#item_"+id).text());
			$("#gift").append($html.html().replace(/{itemid}/gm,id));
		});
		$.tbox.close();
	}
}
</script>